<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>莫伊の测试笔记</title><meta name="author" content="莫伊"><meta name="copyright" content="莫伊"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="幸运交给锦鲤，你只管努力就好">
<meta property="og:type" content="website">
<meta property="og:title" content="莫伊の测试笔记">
<meta property="og:url" content="https://mooii.gitee.io/page/3/index.html">
<meta property="og:site_name" content="莫伊の测试笔记">
<meta property="og:description" content="幸运交给锦鲤，你只管努力就好">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100">
<meta property="article:author" content="莫伊">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100"><link rel="shortcut icon" href="https://mooii.oss-cn-shanghai.aliyuncs.com/%E3%83%AA%E3%82%B9%E3%81%AE%E3%82%A2%E3%82%A4%E3%82%B3%E3%83%B3%E3%81%A7%E3%81%99%E3%81%9F%E3%81%84%E3%80%82.png"><link rel="canonical" href="https://mooii.gitee.io/page/3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '莫伊の测试笔记',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-05-26 16:00:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiperstyle.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.css"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.min.css" media="defer" onload="this.media='all'"><script async src="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus@latest/lib/carousel-touch.min.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('https://mooii.oss-cn-shanghai.aliyuncs.com/20211021164956.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">莫伊の测试笔记</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">莫伊の测试笔记</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/12/06/pytest15/"><div class="article-content-text">feature和story的区别 二者区别 
              
              featurestoryfeature相当于一个功能，一个大的模块将case分类到某个feature中，在报告中的behavior中显示作用相当于testsuite&lt;/ul&gt;&lt;/div&gt;story相当于对应这个功能或者模块下的不同场景（or分支功能）属于feature之下的结构，在报告中的feature中显示作用相当于testcase&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;123456789@allure.feature(&quot;登录模块&quot;)class TestSearch():    @allure.story(&quot;登录成功&quot;)    def test_case1(self):        print(&quot;登录成功&quot;)    @allure.story(&quot;登录失败&quot;)    def test_case2(self):        p ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/12/06/pytest15/"><div class="article-title-link">Pytest系列15-allure特性feature、story、step使用说明</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-12-06T15:50:36.000Z" title="发表于 2021-12-06 23:50:36">2021-12-06</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/11/30/pytest14/"><div class="article-content-text">作用可以在测试报告中看到测试功能、子功能/场景、测试步骤以及测试附件信息等
常用特性 allure.feature 
              
              作用使用方法为测试模块添加功能名称说明使用方法：在测试模块前加上@allure.feature(&quot;模块说明&quot;)即可
              
            
 allure.story 
              
              作用使用方法为测试方法添加子功能名称说明使用方法：在测试方法前增加@allure.story(&quot;子功能说明&quot;)即可
              
            
 allure.step 
              
              作用使用方法添加测试步骤说明使用方法：在对应的测试步骤前增加with allure.step(&quot;测试步骤&quot;)即可
              
            
 allure.attach 
              
        ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/30/pytest14/"><div class="article-title-link">Pytest系列14-allure常用特性</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-30T14:39:58.000Z" title="发表于 2021-11-30 22:39:58">2021-11-30</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5372(20211213-233028).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/11/29/pytest13/"><div class="article-content-text">allure的好处
好看！！！🤣🤣🤣（可能对于颜值党来说，这个比较重要）
可以通过装饰器拓展功能
给领导演示的时候，测试报告美观、直接、清晰
allure完美符合上述n点

allure安装配置 配置环境变量 
              
              STEP1STEP2STEP3先去git上下载最新版，👉传送门下载后解压到本地，记住这个解压路径将bin目录配置到环境变量中，保存即可安装插件：pip install allure-pytest按照以上步骤，我们的准备工作就做好啦~~~
              
            
allure的使用在执行脚本文件时，使用参数--alluredir，来手机测试结果并指向对应的文件夹即可，即在命令行输入
1pytest xx.py -qs --alluredir=./result
输入之后运行，我们会得到一堆杂七杂八的文件，如下图

然鹅这并不是我们想要的，要查看测试报告，我们需要通过其他的方式
 查看测试报告 
              
              方法一方法二测试完成后，查看实际报 ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/29/pytest13/"><div class="article-title-link">Pytest系列13-pytest生成报告插件pytest-allure</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-29T14:18:01.000Z" title="发表于 2021-11-29 22:18:01">2021-11-29</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5375(20211213-233124).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/11/29/pytest12/"><div class="article-content-text">安装插件国际惯例，使用插件之前需要先安装插件
安装方式：pip install pytest-html
使用方法执行测试文件时加上相关参数即可
比如，命令行输入
12# pytest -sv --html=测试报告的路径/报告名称 xx.pypytest --html=./HtmlReport/testhtml.html TestSkip.py
可以看到，在当前目录下的HTMLreport的文件夹下成功生成报告

生成的报告效果如下：

</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/29/pytest12/"><div class="article-title-link">Pytest系列12-pytest生成测试报告插件pytest-html</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-29T13:53:09.000Z" title="发表于 2021-11-29 21:53:09">2021-11-29</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5375(20211213-233124).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/11/28/pytest11/"><div class="article-content-text">安装插件安装方法：
1pip install pytest-rerunfailures
使用方法命令行参数重试次数间隔时间
指定重试次数： —reruns n 

12#表示运行失败的用例重新运行2次pytest --reruns2
指定间隔时间：—reruns-delay m 

12#表示运行失败的用例重新运行2次，执行时时间间隔为5spytest --reruns2 --reruns-delay 5
举个小栗子，代码如下👇
1234567def test1():    b = 1+2    assert 3==bdef test2():    b = 1+2    assert 2 == b
命令行输入：
1pytest --reruns 2 --reruns-delay 3 filename.py
运行结果如下：

使用装饰器使用方法：@pytest.mark.flaky(reruns=重试次数,reruns_delay=延时设置（单位为秒)
12345678def test1():    b = 1+2    assert 3==b@pytest.mark.flaky(re ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest11/"><div class="article-title-link">Pytest系列11-失败重跑插件rerunfailures</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:20:05.000Z" title="发表于 2021-11-28 15:20:05">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/11/28/pytest10/"><div class="article-content-text">前言从字面意思来理解，就是跳过测试——用于不想执行的代码
用法例如：@pytest.mark.skip(reason=”不想执行的原因，执行时会输出reason内容”)

pytest.mark.skip使用skip标记用例，可以跳过对应用例的执行
pytest.mark.skip可以加在函数、类、方法上

标记在函数方法上123@pytest.mark.skip(reason=&quot;我不想执行Test1&quot;)def test1(self):    print(&quot;这里是test case1,但是我不想执行&quot;)
执行结果如下：

标记在类上1234@pytest.mark.skip(reason=&quot;标记在类上，测试类不会被执行哦&quot;)class TestSkip:    def test1(self):        print(&quot;这里是test case1&quot;)
执行结果如下：

在测试期间强行跳过类似于在循环中，如果满足某些条件，则break跳出循环，举个栗子👇
12345def test3(self):     ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest10/"><div class="article-title-link">Pytest系列10-skip、skipif跳过执行用例</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:19:55.000Z" title="发表于 2021-11-28 15:19:55">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/11/28/pytest09/"><div class="article-content-text">实际应用
conftest.py是一个专门存放fixture的配置文件
多人开发时，公共的模块要在不同的文件中使用（比如多个用例都需要用到登录功能来作为前置操作）
可以将全局的fixture放在conftest.py文件中进行管理

使用方法
一般项目下全局的数据共享的地方

注意事项
conftest文件名是固定的，不能更换！！！
conftest文件放在不同的文职起着不同的范围共享作用（如放在项目下则是全局的数据共享的地方）
一个项目中可以有多个conftest.py文件
不同的目录可以有自己的conftest.py
conftest.py不需要手动import，pytest在执行时会自动查找

如果有多个conftest.py，那么运行时采取就近生效的原则（先在同级目录找，同级目录没有则向上级目录查找）


</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest09/"><div class="article-title-link">Pytest系列09-conftest.py文件的用途</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:19:45.000Z" title="发表于 2021-11-28 15:19:45">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5372(20211213-233028).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/11/28/pytest08/"><div class="article-content-text">fixture的应用场景
比如在自动化的过程中，有的用例需要登录才能执行，有的用例不需要登录，这种场景setup和teardown比较难满足，fixture可以满足这种场景

fixture优点
命令灵活：对于setup和teardown，可以不起这两个名字
数据共享：在conftest.py配置李写方法可以实现数据共享，不需要import导入
scope的层次及与yield组合相当于各种setup和teardown

fixture参数123@pytest.fixture(scope=&quot;function&quot;, params=None, autouse=False, ids=None, name=None)def test():    print(&quot;fixture初始化的参数列表&quot;)
参数列表
scope：即作用域，默认function，常用class、module、package、session（整个项目）
autouse：默认false，若设置为true，则所有的测试用例执行前会自动调用该fixture

使用方法定义
使用装饰器来定义fixt ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest08/"><div class="article-title-link">Pytest系列08-fixture的用法</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:19:35.000Z" title="发表于 2021-11-28 15:19:35">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content left"><a class="article-content" href="/2021/11/28/pytest07/"><div class="article-content-text">pytest.ini规则
pytest.ini是pytest的主配置文件，一般放在项目工程的根目录
可以指定pytest的运行方式
不能使用任何中文字符！！！（windows）

常用配置项1234567[pytest]markers			自定义mark 标签名addopts			运行时参数（可添加过个，所有参数与命令行一致）python_files	自定义测试文件命名规则python_classes  = Test_*	自定义测试类命名规则python——function = test_*	自定义测试方法命名规则norecursedirs = result log datas test_demo* 	运行时忽略某些文件夹
</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest07/"><div class="article-title-link">Pytest系列07-配置文件pytest.ini的使用</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:19:22.000Z" title="发表于 2021-11-28 15:19:22">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><div class="recent-post-item"><div class="recent-post-content right"><a class="article-content" href="/2021/11/28/pytest06/"><div class="article-content-text">mark的作用
可以把一个项目划分为多个模块，然后通过指定模块名称执行对应的用例

mark用法@pytest.mark.xxx标记用例即可
🐋 ATTENTION：

标记名最好有意义
同一个测试类/方法可以同时拥有多个标记

话不多说，我们直接上代码👇👇👇
123456789101112131415161718192021222324252627282930313233343536# -*- coding: utf-8 -*-# @Author : Mooii# @Time : 2021/11/15# @File : TestMark.py# @Description :标记mark的使用# test_login_logout.pyimport pytest@pytest.mark.loginclass TestLogin:    &quot;&quot;&quot;登陆测试类&quot;&quot;&quot;    @pytest.mark.smoke    @pytest.mark.success    def test_login_sucess(self):     ...</div></a><div class="recent-post-info"><a class="article-title" href="/2021/11/28/pytest06/"><div class="article-title-link">Pytest系列06-标记mark的使用</div></a><div class="recent-post-meta">               <div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-11-28T07:17:48.000Z" title="发表于 2021-11-28 15:17:48">2021-11-28</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/Pytest/">Pytest</a></span></div></div></div><div class="recent-post-cover"><img class="article-cover" src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'"></div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/page/2/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/#content-inner">2</a><span class="page-number current">3</span><a class="page-number" href="/page/4/#content-inner">4</a><a class="extend next" rel="next" href="/page/4/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">莫伊</div><div class="author-info__description">幸运交给锦鲤，你只管努力就好</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">35</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">6</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">4</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mooii"><i class="https://mooii.oss-cn-shanghai.aliyuncs.com/20211021164956.png"></i><span>我的主页</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">人生有限，接受事与愿违！！！</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/05/25/python06/" title="python06-输入与输出"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5373(20211213-233042).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python06-输入与输出"/></a><div class="content"><a class="title" href="/2022/05/25/python06/" title="python06-输入与输出">python06-输入与输出</a><time datetime="2022-05-25T14:40:00.000Z" title="发表于 2022-05-25 22:40:00">2022-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/05/25/python05/" title="python05-字典和集合"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5370(20211213-232951).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python05-字典和集合"/></a><div class="content"><a class="title" href="/2022/05/25/python05/" title="python05-字典和集合">python05-字典和集合</a><time datetime="2022-05-25T14:20:14.000Z" title="发表于 2022-05-25 22:20:14">2022-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/04/10/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%9501/" title="性能测试01-性能测试中各种指标的关系"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="性能测试01-性能测试中各种指标的关系"/></a><div class="content"><a class="title" href="/2022/04/10/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%9501/" title="性能测试01-性能测试中各种指标的关系">性能测试01-性能测试中各种指标的关系</a><time datetime="2022-04-10T15:17:35.000Z" title="发表于 2022-04-10 23:17:35">2022-04-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/01/09/python04/" title="python04-文件读取"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5371(20211213-233011).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python04-文件读取"/></a><div class="content"><a class="title" href="/2022/01/09/python04/" title="python04-文件读取">python04-文件读取</a><time datetime="2022-01-09T15:03:14.000Z" title="发表于 2022-01-09 23:03:14">2022-01-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/01/09/python03/" title="python03-字符串常用函数"><img src="https://mooii.oss-cn-shanghai.aliyuncs.com/IMG_5374(20211213-233104).PNG" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="python03-字符串常用函数"/></a><div class="content"><a class="title" href="/2022/01/09/python03/" title="python03-字符串常用函数">python03-字符串常用函数</a><time datetime="2022-01-09T15:02:17.000Z" title="发表于 2022-01-09 23:02:17">2022-01-09</time></div></div></div></div><div class="card-widget" id="card-newest-comments"><div class="item-headline"><i class="fas fa-comment-dots"></i><span>最新评论</span></div><div class="aside-list"><span>正在加载中...</span></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Pytest/"><span class="card-category-list-name">Pytest</span><span class="card-category-list-count">20</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Python/"><span class="card-category-list-name">Python</span><span class="card-category-list-count">6</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Selenium/"><span class="card-category-list-name">Selenium</span><span class="card-category-list-count">8</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/"><span class="card-category-list-name">性能测试</span><span class="card-category-list-count">1</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/Pytest/" style="font-size: 1.5em; color: #99a9bf">Pytest</a> <a href="/tags/Python/" style="font-size: 1.23em; color: #999ea6">Python</a> <a href="/tags/Selenium/" style="font-size: 1.37em; color: #99a4b2">Selenium</a> <a href="/tags/UI%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 1.37em; color: #99a4b2">UI自动化</a> <a href="/tags/%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95/" style="font-size: 1.1em; color: #999">性能测试</a> <a href="/tags/%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6/" style="font-size: 1.5em; color: #99a9bf">测试框架</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/05/"><span class="card-archive-list-date">五月 2022</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/04/"><span class="card-archive-list-date">四月 2022</span><span class="card-archive-list-count">1</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/01/"><span class="card-archive-list-date">一月 2022</span><span class="card-archive-list-count">4</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/12/"><span class="card-archive-list-date">十二月 2021</span><span class="card-archive-list-count">14</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/11/"><span class="card-archive-list-date">十一月 2021</span><span class="card-archive-list-count">13</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/10/"><span class="card-archive-list-date">十月 2021</span><span class="card-archive-list-count">1</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">35</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2021-11-17T16:00:00.000Z"></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2022-05-26T08:00:45.808Z"></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 莫伊</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">好好学习🧡天天学习</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><div class="js-pjax"><script>function subtitleType () {
  getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => {
    jinrishici.load(function (result) {
      if (true) {
        var sub = "".length == 0 ? new Array() : "".split(',')
        var content = result.data.content
        var both = sub.unshift(content)
        var typed = new Typed('#subtitle', {
          strings: sub,
          startDelay: 300,
          typeSpeed: 150,
          loop: true,
          backSpeed: 50,
        })
      } else {
        document.getElementById('subtitle').innerHTML = result.data.content
      }
    })
  })
}

if (true) {
  if (typeof Typed === 'function') {
    subtitleType()
  } else {
    getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
  }
} else {
  subtitleType()
}
</script></div><script data-pjax defer src="/js/custom/fixed_card_widget.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><div id="fixedcard-dashboard"><button class="fixedcard-activebtn" type="button" title="用户信息" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-info&quot;,&quot;0&quot;)"><i class="fas fa-address-book"></i></button><button class="fixedcard-activebtn" type="button" title="电子钟" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-clock&quot;,&quot;0&quot;)"><i class="fas fa-cloud-sun"></i></button><button class="fixedcard-activebtn" type="button" title="碎碎念" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-shuo&quot;,&quot;0&quot;)"><i class="fas fa-comments"></i></button><button class="fixedcard-activebtn" type="button" title="最新文章" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-recent-post&quot;,&quot;0&quot;)"><i class="fas fa-history"></i></button><button class="fixedcard-activebtn" type="button" title="最新评论" onclick="FixedCardWidget(&quot;id&quot;,&quot;card-newest-comments&quot;,&quot;0&quot;)"><i class="fas fa-comment-dots"></i></button><button class="fixedcard-activebtn" type="button" title="标签" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-tags&quot;,&quot;0&quot;)"><i class="fas fa-tags"></i></button><button class="fixedcard-activebtn" type="button" title="网站咨询" onclick="FixedCardWidget(&quot;class&quot;,&quot;card-webinfo&quot;,&quot;0&quot;)"><i class="fas fa-chart-line"></i></button><div class="fixedcard-user-avatar fixedcard-activebtn" onclick="RemoveFixedCardWidget()"><img class="fixedcard-user-avatar-img" src="https://portrait.gitee.com/uploads/avatars/user/1627/4881517_lolien_1621782146.png!avatar100" title="莫伊"></div></div></div><!-- hexo injector body_end start --> <script data-pjax>if(document.getElementById('recent-posts') && location.pathname =='/'){
    
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms"></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载swiper')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.js"></script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper@0.18/swiper/swiperindex.js"></script>
<style></style><script data-pjax>function electric_clock_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = 'undefined';
                console.log('已挂载electric_clock')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            electric_clock_injector_config()
        } </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax  src="https://cdn.jsdelivr.net/gh/Zfour/hexo-electric-clock@1.0.6/clock.js"></script><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>